<?php
namespace app\common\model;
use app\common\model\CommonModel;
use think\Db;

class Stock extends CommonModel
{
	/**
	* 商品入库信息
	*/
	public function serStock($data)
	{
		return $this->insert($data);
	}
	/**
	* 获取库存信息列表
	*/
	public function getStockList($where,$field,$limit,$page,$group = 's.stock_id')
	{
	   $item = $this->alias('s')
				->join('mps_goods g','s.goods_id = g.goods_id')
				->where($where)->field($field)
                ->group($group)
                ->order('s.addtime DESC')
				->paginate($limit,false,['page'=>$page]);
       return empty($item) ? array():$item->toArray();
	}
	/**
	* 获取库存信息
	*/
	public function stockList($where,$field,$group = 's.stock_id',$find = 'select')
	{
	   $item = $this->alias('s')
				->join('mps_goods g','s.goods_id = g.goods_id')
				->where($where)->field($field)
                ->group($group)
				->$find();
       return empty($item) ? array():$item->toArray();
	}	
	/**
	* 删除
	*/
	public function delStorage($where)
	{
		return $this->where($where)->delete();
	}
	/**
	* 修改信息
	*/
	public function updateStorage($where,$data)
	{
		return $this->where($where)->update($data);
	}
    /**
	* 获取字段信息
	*/
	public function fieldStorage($where,$field)
	{
		return $this->where($where)->value($field);
	}
	/**
	* 获取信息
	*/
	public function getStockInfo($where)
	{
		$item = $this->where($where)->find();
        return empty($item) ? array():$item->toArray();
	}
    /**
    * 库存数量
    */
    public function stockNumber($where)
    {
        return $this->where($where)->sum('number');
    }
}
